package cn.dkdoo.utils.config.rollbackData.template;

import cn.dkdoo.utils.config.rollbackData.RollbackDataSelf;
import cn.dkdoo.utils.config.rollbackData.RollbackDetail;
import cn.dkdoo.utils.config.transactionInfo.TransactionInfoAbstract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Map;

/**
 * Created by Nicky.Tang on 2021/5/11 10:23 下午
 *
 * @since 02.12.10
 */
public abstract class RollbackTemplateAbstract<T> {
    private static final Logger logger = LoggerFactory.getLogger(RollbackTemplateAbstract.class);
    protected T template;
    protected String beanName;

    public RollbackTemplateAbstract(T template, String beanName) {
        this.template = template;
        this.beanName = beanName;
    }

    public RollbackTemplateAbstract(T template) {
        this.template = template;
    }

    //    abstract T getTemplate();

    protected final void addRollbackData(RollbackDataSelf rollbackDataSelf) {
        TransactionInfoAbstract.addRollbackDataStatic(rollbackDataSelf);
    }

    protected final void addRollbackData(String collectionName, Map<String, RollbackDetail> datasCur) {
        TransactionInfoAbstract.addRollbackDataStatic(collectionName, this.beanName, null, datasCur);
    }

    protected final void addRollbackData(String collectionName, String dataClass, Map<String, RollbackDetail> datasCur) {
        TransactionInfoAbstract.addRollbackDataStatic(collectionName, this.beanName, dataClass, datasCur);
    }

    protected final void addRollbackData(String methodName, Collection<?> args) {
        RollbackDataSelf rollbackDataSelf = new RollbackDataSelf(this.beanName, methodName, args);
        TransactionInfoAbstract.addRollbackDataStatic(rollbackDataSelf);
    }


}
